package com.gdyzy.controller;

import com.gdyzy.dto.UserDto;
import com.gdyzy.pojo.User;
import com.gdyzy.service.UserService;
import com.gdyzy.common.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/users")
@Slf4j
public class UserController {

    @Autowired
    private UserService userService;

    /*@PostMapping
    public R<User> login(@RequestBody Map map) {
        log.info("phone: {}", map.get("phone").toString());
        String phone = map.get("phone").toString();
        User user = userService.findByPhone(phone);
        if (user == null) {
            return R.error("找不到该用户");
        }
        return R.success("通过手机号码查询用户成功", user);
    }*/

    @PostMapping
    public R<UserDto> login(@RequestBody Map map) {
        log.info("phone: {}", map.get("phone").toString());
        String phone = map.get("phone").toString();
        UserDto userDto = userService.findByPhone(phone);
        if (userDto == null) {
            return R.error("找不到该用户");
        }
        return R.success("通过手机号码查询用户成功", userDto);
    }
}
